<%@ page language="java" pageEncoding="UTF-8"%>
<%@page import="java.util.List"%>
<%@page import="com.shsh.safemanage.action.PostcheckReportAction"%>
<%@page import="com.shsh.safemanage.action.ActionCreator"%>
<%@page import="com.shsh.safemanage.model.PostCheck"%>
<%@page import="com.shsh.safemanage.model.User"%>
<%@page import="com.shsh.safemanage.dao.PostCheckDao"%>
<%@page import="com.shsh.safemanage.dao.DaoCreator"%>
<%@page import="com.shsh.safemanage.util.Constants"%>
<%@page import="com.shsh.safemanage.util.Util"%>
<%
{
	
	Long postcheckID = 0l;
	Integer year = 0;
	Integer month = 0;
	String postcheckIDStr = (String)request.getParameter(Constants.REQUEST_PARAMETER_POSTCHECK_ID);
	
	try{
		postcheckID = Long.parseLong(postcheckIDStr);
	} catch (Exception e){
		
	}
	
	try{
		year = Integer.parseInt(request.getParameter(Constants.REQUEST_PARAMETER_YEAR));
	}catch(Exception e){
		
	}
	
	
	try{
		month = Integer.parseInt(request.getParameter(Constants.REQUEST_PARAMETER_MONTH));
	}catch(Exception e){
		
	}
	
	PostCheckDao postcheckDao = DaoCreator.createPostCheckDao();
	PostCheck postcheck = postcheckDao.getPostCheck(postcheckID);
	if (postcheck == null){
	%>
		<script type="text/javascript">
		loadPageSection('<%=request.getContextPath()%>/user_info.jsp', 'mainContentDiv');
		</script>
	<%
	}
	int monthEnd = Util.getMonthEnd(year, month);
	
	User sessionUser = (User)session.getAttribute(Constants.SESSION_USER);
	
	PostcheckReportAction reportAction = ActionCreator.createPostcheckReportAction();
	Object[][] reportTable = (Object[][])application.getAttribute(Constants.APPLICATION_POSTCHECK_SUMMARY_REPORT_TABLE + "_" + postcheckID + "_" + year + "_" + month);
	Integer department1Count = (Integer)application.getAttribute(Constants.APPLICATION_DEPARMENT1_COUNT);
	boolean isSuccess = false;
	if(reportTable == null) {
		isSuccess = reportAction.generatePostcheckSummaryReport(request);
		reportTable = (Object[][])application.getAttribute(Constants.APPLICATION_POSTCHECK_SUMMARY_REPORT_TABLE + "_" + postcheckID + "_" + year + "_" + month);
		department1Count = (Integer)application.getAttribute(Constants.APPLICATION_DEPARMENT1_COUNT);
	}
%>
<div class="hider" id="hider">
	<span>&nbsp;</span>
</div>
<div class="position">
	<img src="images/position2.jpg" style="padding: 7px 9px; float: left;" />当前位置：上海高桥分公司问题管理平台 &gt;&gt; <%=postcheck.getCheckName() %>岗检 &gt;&gt;<%=postcheck.getCheckName() %>记录情况一览表
</div>
<div class="tt">《高桥石化<%=postcheck.getCheckName() %>岗检记录情况一览表》</div>
<div class="content" style="width:1834px;height:415px;">
	<div style="margin-left: 10px">
	<span id="monthSelectSpan" style="margin-left: 10px;float:left;">	
	<%@include file="/postcheck_select/month_select_section.jsp" %>
	</span>
	</div>
	<table border="1" width="100%" style="align:center; margin-left: 6px">
		<tr>
			<td style="text-align:center;" width="7%" class="td3">
				部门
			</td>
			<%
			for (int day = 1; day <= monthEnd; day ++){
			%>			
			<td style="text-align:center;" width="3%" class="td3">
				<%=day %>
			</td>
			<%
			}
			%>
		</tr>
		<%for(int departmentIndex = 0; departmentIndex <department1Count ; departmentIndex ++) {
			Object[] dailyReport = reportTable[departmentIndex];
			String deparment1Name = (String)dailyReport[0];
		%>
		<tr>
			<td style="text-align:center;" class="td3">
				<%=deparment1Name %>
			</td>
			<%
			for (int day = 1;day<=monthEnd;day++){
				List<User> userLst = (List<User>)dailyReport[day];
			%>
			<td style="text-align:left;" class="td3">
				<%
				if (userLst.isEmpty()) {
				%>
				&nbsp;
				<%
				} else {
					for(int uIndex=0;uIndex<userLst.size()-1;uIndex++) {
						User user = userLst.get(uIndex);
				%>
				<a href="javascript:" onclick="openPostcheckUserDailyReport(<%=day%>,<%=user.getId()%>, <%=user.getDepartment1ID()%>)"><%=user.getName() %></a>、
				<%
					}
					User user = userLst.get(userLst.size()-1);
				%>
				<a href="javascript:" onclick="openPostcheckUserDailyReport(<%=day%>,<%=user.getId()%>, <%=user.getDepartment1ID()%>)"><%=user.getName() %></a>
				<%
				}
				%>
			</td>
			<%
			}
			%>		
		</tr>
		<%} %>
		<tr>	
			<td colspan="<%=monthEnd+1 %>" style="text-align:center;" width="100%" class="td3">
				
			</td>
		</tr>
	</table>
</div>
<script type="text/javascript">
function goBack(){
	loadPageSection('<%=request.getContextPath()%>/postcheck_browse_entrance.jsp', 'mainContentDiv', {postcheckID: <%=postcheck.getId() %>}, true);
}

function openPostcheckMonthReport() {
	var year = getElementValueByID("year");
	var month = getElementValueByID("month");
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/report/postcheck_month_report.jsp', 
			'mainContentDiv', 
			{
				postcheckID: <%=postcheck.getId() %>, 
				year: year,
				month: month,
				display: '0'
			}, 
			true
	);
}

function selectYear() {
	var year = getElementValueByID("year");
	var month = getElementValueByID("month");
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/report/postcheck_summary_report.jsp', 
			'mainContentDiv', 
			{
				postcheckID: <%=postcheck.getId() %>,
				year: year,
				month: month
			}, 
			true
		);
}

function selectMonth() {
	var year = getElementValueByID("year");
	var month = getElementValueByID("month");
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/report/postcheck_summary_report.jsp', 
			'mainContentDiv', 
			{
				postcheckID: <%=postcheck.getId() %>,
				year: year,
				month: month
			}, 
			true
		);
}

function openPostcheckUserDailyReport(day, userID, userDepart1ID){
	loadPageSection(
			'<%=request.getContextPath()%>/postcheck/report/postcheck_user_daily_report.jsp', 
			'mainContentDiv', 
			{
				fromPage: 'postcheck/report/postcheck_summary_report',
				postcheckID: <%=postcheck.getId() %>,
				depart1ID: userDepart1ID,
				userID: userID, 
				year: <%=year%>, 
				month: <%=month%>,
				day: day
			}, 
			true);
}

</script>
<%
}
%>